#ifndef IEC_TYPES_H
#define IEC_TYPES_H

//#include <limits.h>
#include <float.h>
//#include <stdint.h>
#ifndef XMC1100
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#endif
#define __IEC_DEBUG_FLAG 0x01
#define __IEC_FORCE_FLAG 0x02
#define __IEC_RETAIN_FLAG 0x04
#define __IEC_OUTPUT_FLAG 0x08
#define __IEC_MODIFY_FLAG 0x10
/*********************/
/*  IEC Types defs   */
/*********************/

typedef unsigned char IEC_BOOL;

typedef char IEC_SINT;
typedef short IEC_INT;
typedef int IEC_DINT;
typedef long int IEC_LINT;

typedef unsigned char IEC_USINT;
typedef unsigned short IEC_UINT;
typedef unsigned int IEC_UDINT;
typedef unsigned long int IEC_ULINT;

typedef unsigned char IEC_BYTE;
typedef unsigned short IEC_WORD;
typedef unsigned int IEC_DWORD;
typedef unsigned long int IEC_LWORD;

typedef float IEC_REAL;
typedef double IEC_LREAL;

/* WARNING: When editing the definition of IEC_TIMESPEC, take note that 
 *          if the order of the two elements 'tv_sec' and 'tv_nsec' is changed, then the macros 
 *          __time_to_timespec() and __tod_to_timespec() will need to be changed accordingly.
 *          (these macros may be found in iec_std_lib.h)
 */
typedef struct {
    long int tv_sec;            /* Seconds.  */
    long int tv_nsec;           /* Nanoseconds.  */
} /* __attribute__((packed)) */ IEC_TIMESPEC;  /* packed is gcc specific! */

typedef IEC_TIMESPEC IEC_TIME;
typedef IEC_TIMESPEC IEC_DATE;
typedef IEC_TIMESPEC IEC_DT;
typedef IEC_TIMESPEC IEC_TOD;

#ifndef STR_MAX_LEN
#define STR_MAX_LEN 126
#endif

#ifndef STR_LEN_TYPE
#define STR_LEN_TYPE char
#endif

#define __INIT_REAL 0
#define __INIT_LREAL 0
#define __INIT_SINT 0
#define __INIT_INT 0
#define __INIT_DINT 0
#define __INIT_LINT 0
#define __INIT_USINT 0
#define __INIT_UINT 0
#define __INIT_UDINT 0
#define __INIT_ULINT 0
#define __INIT_TIME (TIME){0,0}
#define __INIT_BOOL 0
#define __INIT_BYTE 0
#define __INIT_WORD 0
#define __INIT_DWORD 0
#define __INIT_LWORD 0
#define __INIT_STRING (STRING){0,""}
//#define __INIT_WSTRING
#define __INIT_DATE (DATE){0,0}
#define __INIT_TOD (TOD){0,0}
#define __INIT_DT (DT){0,0}

typedef STR_LEN_TYPE __strlen_t;
typedef struct {
    __strlen_t len;
    unsigned char body[STR_MAX_LEN];
} /* __attribute__((packed)) */ IEC_STRING;  /* packed is gcc specific! */

#endif /*IEC_TYPES_H*/
